//
//  Bank.c
//  博客代码
//
//  Created by 马鹏朔 on 2022/11/5.
//

#include "Bank.h"
   void InitBank(Bank*pls)
{
     assert(pls);//这个是防止传入空指针
      pls->data[1]=(User){"小马","男",18,"412XXXX","18XXXX","123456",1300.0};
     pls->data[2]=(User){"小李","男",17,"413XXXX","17XXXX","1234567",1200.0};
     pls->data[3]=(User){"小王","女",20,"423XXXX","15XXXX","12345678",1100.0};
      pls->size=4;
      //这里是原本在银行里的用户
    
    //这里是给
}
int  Login(char*arr1,char*arr2,Bank* pls,int size)
{
    int i=1;
    for(i=1;i<size;i++)
    {
        if((strcmp(arr1,pls->data[i].cardNo)||strcmp(arr2,pls->data[i].password))==0) //这就是用来判断你输入的身份证和密码是否存在 运用了strcmp函数 注意别忘了引用库函数
        {
            return i;
        }
    }
    return 0;
}
void getBalance(double m,int ret,Bank*pls)//m为输入的金额 ret就是返回的下标
{
    if(m>0&&m<100000)
    {
        pls->data[ret].balance=pls->data[ret].balance+m;
        printf("存钱成功，现在有余额为：%.2f\n",pls->data[ret].balance);
    }
    else{
        printf("存钱失败\n");
    }
}
void setBalance(double n,int ret,Bank*pls)
{
    if(n>0&&n<=pls->data[ret].balance)//首先取钱不能为负再者取钱金额不能大于你的余额
    {
        pls->data[ret].balance=pls->data[ret].balance-n;
        printf("取钱成功，现在有余额为：%.2f\n",pls->data[ret].balance);
    }
    else{
        printf("取钱失败\n");
    }
}
void Transfer(double x,int ret1,int ret,Bank*pls)
{
    if(x>0&&x<=pls->data[ret].balance)
    {
        pls->data[ret].balance=pls->data[ret].balance-x;
        pls->data[ret1].balance=pls->data[ret1].balance+x;
        printf("转钱成功，现在有余额为：%.2f\n",pls->data[ret].balance);
    }
    else
    {
        printf("输入金额有误\n");
    }
}
void ChangePassword(char *arr6,int ret,Bank*pls)
{
    strcpy(pls->data[ret].password,arr6);
}
